<template>
  <div class="drawer_box">
    <!-- <div class="drawer_text" style="margin-bottom: 10px;">{{ CriminalInfoSelectText }}</div> -->
    <div class="" style="transform: translate(0px, -4px)">
  
    </div>

    <div class="isTable flex_start_start">

      <el-table
        :data="yjwzArr"
        border
        fit
        :span-method="mergeCells"
        highlight-current-row
        stripe
        style="width: 100%"
        height="700"
      >
   
    <!--  <el-table-column label="监区" align="center" width="120">
          <template #default="scope">
            <div>
              {{ scope.row.orgName }}
            </div>
          </template>
        </el-table-column> -->

        <el-table-column label="类型" align="center" width="140">
          <template #default="scope">
            <div>
              {{ scope.row.typeName }}
            </div>
          </template>
        </el-table-column>

        <el-table-column label="名称" align="center" width="140">
          <template #default="scope">
            <div>
              {{ scope.row.name }}
            </div>
          </template>
        </el-table-column>

        <el-table-column label="数量" align="center" width="60">
          <template #default="scope">
            <div>
              {{scope.row.rest }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="单位" align="center" width="60">
          <template #default="scope">
            <div>
              {{ scope.row.formatName }}
            </div>
          </template>
        </el-table-column>

        <el-table-column label="时间" align="center" width="160">
          <template #default="scope">
            <div>
              {{ scope.row.createDate.split('T')[0] + ' ' +  scope.row.createDate.split('T')[1].split(':')[0]+
              ':'+scope.row.createDate.split('T')[1].split(':')[1]
              }}
            </div>
          </template>
        </el-table-column>

        <el-table-column label="描述" align="center">
          <template #default="scope">
            <div>
              {{ scope.row.remark }}
            </div>
          </template>
        </el-table-column>


      </el-table>
    </div>
    <!-- <div class="example-pagination-block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            background
            layout="prev, pager, next,total"
            :total="total"
          />
        </div> -->
  </div>
  <div>
    <el-dialog
      top="60px"
      style="height: 648px"
      title="添加"
      v-model="dialogFormVisibleCv"
      width="1152"
    >
      <div
        class=""
        style="margin-top: 10px; height: 537px; box-sizing: border-box"
      >
        <div class="flex_start_start form_item">
          <div class="titles flex_center_center">名称：</div>
          <el-input v-model="inputName" style="width: 340px" placeholder="" />
        </div>
        <div class="flex_start_start form_item">
          <div class="titles flex_center_center">数量：</div>
          <el-input v-model="inputNub" style="width: 340px" placeholder="" />
        </div>
        <div class="flex_start_start form_item">
          <div class="titles flex_center_center">描述：</div>
          <el-input
            type="textarea"
            :rows="4"
            v-model="inputRmake"
            style="width: 340px"
            placeholder=""
          />
        </div>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary"> 保存 </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import http from "@/utils/api";
import {
  Search,
  Share,
  Upload,
  TakeawayBox,
  Refresh,
  Collection,
  Plus,
  Loading,
  FolderDelete,
  Back,
} from "@element-plus/icons-vue";
import {
  ref,
  watch,
  onMounted,
  onBeforeUnmount,
  reactive,
  onBeforeMount,
  nextTick,
  onUnmounted,
  computed
} from "vue";
import { defineProps, defineEmits } from "vue";
const activeName = ref("普管级");
let inputName = ref("");
let inputRmake = ref("");
let inputNub = ref("");
const props = defineProps({
  zfText: {
    type: String,
    default: "",
  },
  orgIds: {
    type: Object,
    default: {},
  },
  jqArr: {
    type: Array,
    default: [],
  },
  dialogVisible16: {
    type: [Object,Boolean],
    default: false,
  },
});

let dialogFormVisibleCv = ref(false);



onBeforeMount(() => {});

let dateSfm = ref("");
let hour = ref("");
let daydata = ref("");
let value3 = ref("");
let years = ref("");
let months = ref("");
let dateArr = ref([]);
// 获取年月日 时
const getFormattedDateTime = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, "0");
  const day = String(now.getDate()).padStart(2, "0");
  const hours = String(now.getHours()).padStart(2, "0");
  const minutes = String(now.getMinutes()).padStart(2, "0");
  const seconds = String(now.getSeconds()).padStart(2, "0");
  dateSfm.value = `${hours}:${minutes}:${seconds}`;
  hour.value = String(now.getHours()).padStart(2, "0");
  daydata.value = `${year}-${month}-${day}`;
  years.value = `${year}`;
  months.value = `${month}`;
  return `${year}-${month}-${day} ${hour.value}`;
};

let datePicker = ref("");
let yjwzArr = ref([]);
let emergencysupplyArr = ref([]);
const getCriminalInfoSelect = async () => {
  let strIds = "";
  let resc = await http.base.sysCmdTree({
    code: "emergencysupply",
    pId: 0,
    type: 24,
    value: "",
  });
  if (resc && resc.code == 0) {
    emergencysupplyArr.value = resc.data;

    if (emergencysupplyArr.value.length) {
      strIds = emergencysupplyArr.value
        .map((item) => {
          return item.id;
        })
        .join(",");
    }
  }

  let res = await http.base.PropertySelect({
    page: 1,
    limit: 999,
    type: strIds,
    name: "",
    ip: "",
    state: "",
    orgId: "",
    isTop: "",
  });
  if (res && res.code == 0) {
    if (res.data.data.length) {
      yjwzArr.value = res.data.data;
      yjwzArr.value = sortedArray.value;
    } else {
      yjwzArr.value = [];
    }
  }
};

const mergeCells = ({ row, column, rowIndex, columnIndex }) => {
  if (columnIndex === 0) {
    // 只合并第一列
    const prevRow = yjwzArr.value[rowIndex - 1];
    const currRow = yjwzArr.value[rowIndex];
    if (prevRow && prevRow.orgName === currRow.orgName) {
      return [1, 0]; // [rowspan, colspan]
    } else {
      const count = 1;
      let mergeCount = 1;
      for (let i = rowIndex + 1; i < yjwzArr.value.length; i++) {
        if (yjwzArr.value[i].orgName === currRow.orgName) {
          mergeCount++;
        } else {
          break;
        }
      }
      return [mergeCount, 1];
    }
  } else {
    return [1, 1];
  }
};


const sortedArray = computed(() => {
  return [...yjwzArr.value].sort((a, b) => a.orgName.localeCompare(b.orgName));
});

const itemClick = (index, item) => {
  dateArr.value.forEach((item) => {
    item.is = false;
  });

  value3.value = item.date;
  getCriminalInfoSelect();
  dateArr.value[index].is = true;
};



watch(
  () => props.dialogVisible16,
  (newValue, oldValue) => {
    if (newValue) {
      getFormattedDateTime();
      datePicker.value = daydata.value;
      value3.value = daydata.value;
      getCriminalInfoSelect();
    } else {
    }
  },
  {
    deep: true, // 深度监听
    immediate: true, // 立即触发回调
  }
);
</script>

<style scoped lang="scss">
::v-deep .el-input__wrapper {
  background: #ffffff0d;
  box-shadow: none;
  color: white;
}
::v-deep .el-input__inner {
  color: white;
}
::v-deep .el-textarea__inner {
  background: #ffffff0d;
  box-shadow: none;
  color: white;
}
.form_item {
  width: 100%;
  height: 40px;
  margin-bottom: 10px;
  color: white;
}
.titles {
  min-width: 60px;
  height: 100%;
}
.nub_box {
  padding-left: 20px;
  color: white;
  font-size: 14px;
}
::v-deep .date_searchbox {
  display: none;
  .el-input__wrapper {
    background-color: rgba(15, 82, 163, 0.278);
    box-shadow: (0 0 0 1px rgba(15, 82, 163, 0.61)) inset;
  }
  .el-input__inner {
    color: white;
  }
  .el-input__prefix {
    color: white;
  }
}

.isAtv {
  background-color: rgb(4 110 250 / 27%) !important;
  font-weight: bold;
}
/**
    分页样式
     */
::v-deep .example-pagination-block {
  margin-top: 10px;
  margin-left: 230px;
  .el-pagination.is-background .btn-prev {
    background-color: #34517d3b;
    color: #ffffff;
  }
  .el-pagination.is-background .el-pager li {
    background-color: #34517d3b;
    color: #ffffff;
  }
  .el-pagination.is-background .btn-next {
    background-color: #34517d3b;
    color: #ffffff;
  }
  .el-pagination__total {
    color: #ffffff;
  }
  .el-pager li.is-active {
    background-color: #0768f9d3 !important;
  }
}
.btn_box {
  width: 10%;
  height: 100%;
  font-size: 16px;
  color: #fff;
  margin-right: 2px;
  .itemz {
    width: 100%;
    height: 30px;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid rgb(5, 112, 146);
    // border-bottom: none;
    border-radius: 4px;
    margin-bottom: 2px;
  }

  .itemz:hover {
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1),
      1px 1px 1px rgba(255, 255, 255, 0.3), 1px 1px 1vmax rgba(0, 0, 0, 0.1);
  }
}
::v-deep .isTable .el-table {
  background-color: rgb(8, 32, 78) !important;
  .el-table tr {
    background-color: rgb(8, 32, 78) !important;
  }
  .cell {
    height: auto;
    color: #fff;
    text-align: center;
    // border: 1px solid #ccc;
    background: rgb(8, 32, 78) !important;
    font-size: 12px;
    line-height: 32px;
  }
  .el-table__cell {
    border-color: 1px solid rgb(5, 112, 146);
    padding: 2px 0px !important;
    background: rgb(8, 32, 78) !important;
  }
  .el-table--fit .el-table__inner-wrapper:before {
    display: none !important;
  }
  .el-table th.el-table__cell.is-leaf {
    border: none !important;
  }
  --el-table-border-color: rgb(5, 112, 146);
}
.drawer_box {
  width: 100%;
  height: 100%;
  position: relative;
  padding: 10px 10px;
  .drawer_text {
    position: absolute;
    top: -23px;
    left: 2px;
    font-size: 18px;
  }
}
</style>
